﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Lib.CommonForm;

namespace AUI
{
    public partial class frmOrderTypeInfo : FormBase
    {
        int _OrderTypeId = 0;
        DataRow m_dr;
        public frmOrderTypeInfo(DataRow dr)
        {
            InitializeComponent();
            

            this.txtOrderTypeCode.MaxLength = tbl_OrderTypes_Length.OrderTypeCode;
            this.txtOrderTypeName.MaxLength = tbl_OrderTypes_Length.OrderTypeName;

            _listRole = tbl_RoleRight_Controller.Instance().GetInfo("LoaiDonHang");
            FormGlobals.Control_SetRequired(txtOrderTypeCode, txtOrderTypeName);
            m_dr = dr;

            if (m_dr != null)
            {
                FormGlobals.Panel_FillData(this, dr);
                _OrderTypeId = Globals.ToInt32(dr["OrderTypeId"]);
            }

            _IsLoading = false;
        }
        public override void Show_Form()
        {
            this.ShowDialog();
        }


        private void btnSave_Click(object sender, EventArgs e)
        {
            tbl_OrderTypes_Info i = new tbl_OrderTypes_Info();
            FormGlobals.Panel_GetData(this, i);
            i.OrderTypeId = _OrderTypeId;
            i.CreateUser = FormGlobals.strUserName;
            i.LastUser = FormGlobals.strUserName;

            txtOrderTypeCode.BackColor = SystemColors.Window;
            if (tbl_OrderTypes_Controller.Instance().IsExist(i))
            {
                txtOrderTypeCode.BackColor = Color.Yellow;
                FormGlobals.Message_Warning(lblOrderTypeCode.Text + UIMessage.EXIST);
                txtOrderTypeCode.Focus();
                return;
            }

            _OrderTypeId = tbl_OrderTypes_Controller.Instance().Save(i);
            if (_OrderTypeId > 0)
            {
                FormGlobals.Message_InTaskbar(UIMessage.SAVE_COMPLETE);
                _dlgResult = DialogResult.OK;
                this.Close();
            }
        }
    }
}
